<?php
/**
 * The Template for displaying all single posts.
 *
 * @package WordPress
 * @subpackage Twenty_Ten
 * @since Twenty Ten 1.0
 */
get_header();
global $post_id;
$post_xml = get_post_meta($post->ID, "cs_event_meta", true);
	if ( $post_xml <> "" ) {
		$xmlObject = new SimpleXMLElement($post_xml);
			$cs_layout = $xmlObject->cs_layout;
			$cs_sidebar_left = $xmlObject->cs_sidebar_left;
			$cs_sidebar_right = $xmlObject->cs_sidebar_right;
			if ( $cs_layout == "left" ) {
				$cs_layout = "two-thirds column right";
				$show_sidebar = $cs_sidebar_left;
			}
			else if ( $cs_layout == "right" ) {
				$cs_layout = "two-thirds column left";
				$show_sidebar = $cs_sidebar_right;
			}
			else $cs_layout = "sixteen columns left";
	}	

	$cs_event_loc = get_post_meta($xmlObject->event_address, "cs_event_loc_meta", true);
	if ( $cs_event_loc <> "" ) {
		$cs_event_loc = new SimpleXMLElement($cs_event_loc);
			$event_loc_lat = $cs_event_loc->event_loc_lat;
			$event_loc_long = $cs_event_loc->event_loc_long;
			$event_loc_zoom = $cs_event_loc->event_loc_zoom;
			$loc_address = $cs_event_loc->loc_address;
			$loc_city = $cs_event_loc->loc_city;
			$loc_postcode = $cs_event_loc->loc_postcode;
			$loc_region = $cs_event_loc->loc_region;
			$loc_country = $cs_event_loc->loc_country;
	}
	else {
		$event_loc_lat = '';
		$event_loc_long = '';
		$event_loc_zoom = '';
		$loc_address = '';
		$loc_city = '';
		$loc_postcode = '';
		$loc_region = '';
		$loc_country = '';
	}
?>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=true"></script>
<script type="text/javascript">
jQuery(document).ready(function($) {
var map;
		var myLatLng = new google.maps.LatLng(<?php echo $event_loc_lat;?>, <?php echo $event_loc_long;?>)
        //Initialize MAP
		var myOptions = {
          zoom: <?php echo $event_loc_zoom;?>,
          center: myLatLng,
		  disableDefaultUI: true,
		  zoomControl: true,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        map = new google.maps.Map(document.getElementById('map_canvas'),myOptions);
		//End Initialize MAP
		//Set Marker
        var marker = new google.maps.Marker({
          position: map.getCenter(),
          map: map
        });
		marker.getPosition();
		//End marker
		
		//Set info window
		var infowindow = new google.maps.InfoWindow({
			content: '',
			position: myLatLng
		});
		infowindow.open(map);
    });
</script>

 	<?php
    if($event_loc_lat <> "" && $event_loc_long <>""){
	?>
		<div id="sub-banner" class="row">  
            <div class="top-cont">                
				<div id="map_canvas"></div>
            </div>
		</div>
	<?php }?>
		<div class="container row">
	        <div class="<?php echo $cs_layout;?>">
					<?php
						//Run the loop to output the post.
                        //get_template_part( 'loop', 'single_cs_event' );
                    ?>
					<?php
                    $cs_event_meta = get_post_meta($post->ID, "cs_event_meta", true);
                    if ( $cs_event_meta <> "" ) $xmlObject = new SimpleXMLElement($cs_event_meta);
                        if ( have_posts() ) while ( have_posts() ) : the_post();
                    ?>
                            <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>                
                                <h1 class="heading"><?php the_title(); ?></h1>                    
                                <div class="in-sec row">
                                    <div class="blog-detail">
                                    <?php
                                    $image_id = get_post_thumbnail_id ( $post->ID );
                                    if($image_id <> ''){
                                        //$image_url = wp_get_attachment_image_src($image_id, array(580,244),true);
                                        $image_url = cs_attachment_image_src($image_id, 580, 244);
                                        ?>
                                            <a class="thumb" style="width:100%; margin-bottom:20px;">
                                                <?php
                                                // getting featured image start
                                                echo "<img src='".$image_url."' />";
                                                // getting featured image end
                                                ?>
                                            </a>
                                            <?php }?>
                                        <div class="blog-opts">
                                            <div class="date">
                                            <h1>
                                                <?php
                                                    $event_from_date = get_post_meta($post->ID, "cs_event_from_date", true);
                                                    $event_to_date = get_post_meta($post->ID, "cs_event_to_date", true);
                                                    echo date( get_option("date_format"), strtotime($event_from_date) );
                                                    if ( $event_from_date < $event_to_date ) {
                                                        echo "<br /> To <br />";
                                                        echo date( get_option("date_format"), strtotime($event_to_date) );
                                                    }
                                                ?>
                                            </h1>
                                            </div>
                                            <div class="desc">
                                                <h4><?php the_title(); ?>
                                                    <?php $categories = get_the_terms( $post->ID, 'event-category' );
                                                        if($categories != ''){?>
                                                            (<?php 
                                                            $couter_comma = 0;
                                                            foreach ( $categories as $category ) {
                                                                echo $category->name;
                                                                $couter_comma++;
                                                                if ( $couter_comma < count($categories) ) {
                                                                    echo ", ";
                                                                }
                                                            }
                                                            ?>)                        
                                                    <?php }?>
                                                </h4>
                                                <p class="by">Posted by <a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>"><?php echo get_the_author();?></a></p>
                                                <p class="coments"><a href="<?php echo get_permalink();?>#comments"><?php echo get_comments_number($post->ID);?> Comments</a></p>
                                                <?php $tag_post = wp_get_post_tags( $post->ID );?>
                                                <p class="tags">
                                                    <?php
                                                    $counterr = 0;
                                                    foreach(get_the_category() as $values){
                                                        if($counterr == 0){ echo 'Category:  ';}
                                                        $counterr++;
                                                        echo '<a href="'.get_category_link($values->term_id).'">'.$values->name.'</a> ';											
                                                        }										
                                                    ?> 
                                                </p>
                                                <p>
                                                    <?php
                                                            echo " ON &nbsp; ";
                                                            // All Day or Specific Time 
                                                            if ( $xmlObject->event_all_day == "" ) {
                                                                echo $xmlObject->event_start_time . " &ndash; " . $xmlObject->event_end_time;
                                                            }
                                                            else {
                                                                echo "All Day";
                                                            }
                                                        ?>
                                                </p>
                                                <p><?php echo ' (Organizer: '.get_the_author().')';?></p>
                                                <p class="by">
													<?php
														if ( $xmlObject->event_address <> "" ) {
															echo get_the_title( "$xmlObject->event_address" );
																if ( $loc_address <> "" ) echo ", " . $loc_address;
																if ( $loc_city <> "" ) echo ", " . $loc_city;
																if ( $loc_postcode <> "" ) echo ", " . $loc_postcode;
																if ( $loc_region <> "" ) echo ", " . $loc_region;
																if ( $loc_country <> "" ) echo ", " . $loc_country;
														}
													?>
                                                </p>
                                                <div class="clear"></div>
                                            </div>
                                        </div>
                                        <div class="blog-desc">
                                            <?php the_content(); ?>
                                            <?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'PixFill' ), 'after' => '</div>' ) ); ?>
                                        </div>
                                        <?php if ( $xmlObject->event_social_sharing == "on" ) { ?>
                                            <div class="blog-sharing">
                                            <div class="sharing right">
                                                <?php 
                                                $cs_social_share = get_option("cs_social_share");
                                                  $xmlObject_album = new SimpleXMLElement($cs_social_share);
                                                    $twitter = $xmlObject_album->twitter;
                                                    $facebook = $xmlObject_album->facebook;
                                                    $linkedin = $xmlObject_album->linkedin;
                                                    $digg = $xmlObject_album->digg;
                                                    $delicious = $xmlObject_album->delicious;
                                                    $google_plus = $xmlObject_album->google_plus;
                                                    $google_buzz = $xmlObject_album->google_buzz;
                                                    $google_bookmark = $xmlObject_album->google_bookmark;
                                                    $myspace = $xmlObject_album->myspace;
                                                    $reddit = $xmlObject_album->reddit;
                                                    $stumbleupon = $xmlObject_album->stumbleupon;
                                                    $yahoo_buzz = $xmlObject_album->yahoo_buzz;
                                                    $rss = $xmlObject_album->rss;
                                                        if($twitter == 'on' or $facebook == 'on' or $linkedin == 'on' or $digg == 'on' or $delicious == 'on' or $google_plus == 'on' or $google_buzz == 'on' or $google_bookmark == 'on' or $myspace == 'on' or $reddit == 'on' or $stumbleupon == 'on' or $yahoo_buzz == 'on' or $rss == 'on'){
                                                            $pageurl = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];?>
                                                            <h6>Share This Post</h6>
                                                            <?php if($twitter == 'on'){?><a href="http://twitter.com/home?status=<?php the_title();?> - <?php echo $pageurl;?>" target="_blank"><img src="<?php echo get_template_directory_uri(); ?>/images/admin/twitter.png" alt="" /></a><?php }?>
                                                            <?php if($facebook == 'on'){?><a href="http://www.facebook.com/share.php?u=<?php the_title();?>" target="_blank"><img src="<?php echo get_template_directory_uri(); ?>/images/admin/facebook.png" alt="" /></a><?php }?>
                                                            <?php if($linkedin == 'on'){?><a href="http://www.linkedin.com/shareArticle?mini=true&#038;url=<?php echo $pageurl;?>&#038;title=<?php the_title();?>" target="_blank"><img src="<?php echo get_template_directory_uri(); ?>/images/admin/linkedin.png" alt="" /></a><?php }?>
                                                            <?php if($digg == 'on'){?><a href="http://digg.com/submit?url=<?php echo $pageurl;?>&#038;title=<?php the_title();?>" target="_blank"><img src="<?php echo get_template_directory_uri(); ?>/images/admin/digg.png" alt="" /></a><?php }?>												
                                                            <?php if($delicious == 'on'){?><a href="http://delicious.com/post?url=<?php echo $pageurl;?>&#038;title=<?php the_title();?>" target="_blank"><img src="<?php echo get_template_directory_uri(); ?>/images/admin/delicious.png" alt="" /></a><?php }?>
                                                            <?php if($google_bookmark == 'on'){?><a href="http://www.google.com/bookmarks/mark?op=edit&#038;bkmk=<?php echo $pageurl;?>&#038;title=<?php the_title();?>" target="_blank"><img src="<?php echo get_template_directory_uri(); ?>/images/admin/google_bookmark.png" alt="" /></a><?php }?>
                                                            <?php if($google_buzz == 'on'){?><a href="http://www.google.com/reader/link?title=<?php the_title();?>&url=<?php the_permalink();?>" target="_blank"><img src="<?php echo get_template_directory_uri(); ?>/images/admin/google_buzz.png" alt="" /></a><?php }?>												
                                                            <?php if($google_plus == 'on'){?><a href="https://plus.google.com/share?url=<?php the_permalink();?>" target="_blank"><img src="<?php echo get_template_directory_uri(); ?>/images/admin/google_plus.png" alt="" /></a><?php }?>																																																
                                                            <?php if($myspace == 'on'){?><a href="http://www.myspace.com/Modules/PostTo/Pages/?u=<?php echo $pageurl;?>" target="_blank"><img src="<?php echo get_template_directory_uri(); ?>/images/admin/myspace.png" alt="" /></a><?php }?>
                                                            <?php if($reddit == 'on'){?><a href="http://reddit.com/submit?url=<?php echo $pageurl;?>&#038;title=<?php the_title();?>" target="_blank"><img src="<?php echo get_template_directory_uri(); ?>/images/admin/reddit.png" alt="" /></a><?php }?>
                                                            <?php if($stumbleupon == 'on'){?><a href="http://www.stumbleupon.com/submit?url=<?php echo $pageurl;?>&#038;title=<?php the_title();?>" target="_blank"><img src="<?php echo get_template_directory_uri(); ?>/images/admin/stumbleupon.png" alt="" /></a><?php }?>
                                                            <?php if($yahoo_buzz == 'on'){?><a href="#" target="_blank"><img src="<?php echo get_template_directory_uri(); ?>/images/admin/yahoo_buzz.png" alt="" /></a><?php }?>                                                                                                                                
                                                            <?php if($rss == 'on'){?><a href="#" target="_blank"><img src="<?php echo get_template_directory_uri(); ?>/images/admin/rss.png" alt="" /></a><?php }?>												
                                                        <?php }?>
                                                </div>
                                            </div>
                                        <?php }?>
                                        <div class="clear"></div>
                                    </div>
                                </div>
                                <div class="clear"></div>
                                <?php if ( get_the_author_meta( 'description' ) ) :?>
                                    <div class="in-sec">
                                        <div class="about-author">
                                            <div class="avatars">
                                                <?php echo get_avatar( get_the_author_meta( 'user_email' ), apply_filters( 'PixFill_author_bio_avatar_size', 53 ) ); ?>
                                            </div>
                                            <div class="desc">
                                                <h5><a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>">About <?php echo get_the_author(); ?></a></h5>
                                                <p class="txt">
                                                    <?php the_author_meta( 'description' ); ?>
                                                </p>
                                                <div class="clear"></div>
                                            </div>
                                            <div class="clear"></div>
                                        </div>
                                    </div>
                                <?php endif; ?>		
                            <?php comments_template( '', true ); ?>
                        </div>
                    <?php endwhile; // end of the loop. ?>

			</div>
			<?php if( $cs_layout != "sixteen columns left" and isset($show_sidebar) ) { ?>
                <div class="one-third column left">
                    <?php
                    	if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar($show_sidebar) ) :
						endif;
					?>
                </div>
            <?php }?>
        </div><!-- #container -->
        <div class="clear"></div>
<?php get_footer(); ?>
<div class="clear"></div>